<div navbar ng-init="currentItem='utils.process'"></div>
<div ng-show="!loaded">
    <div loading></div>
</div>

<div id="main" ng-show="loaded" style="display:none">
    <div class="module-header">
        <h3>进程管理</h3>
    </div>

    <div class="tabbable" ng-init="load()">
        <ul class="nav nav-tabs">
            <li ng-class="'active' | iftrue:activeTabName=='list'"><a href="#list" ng-click="tab_sec('list')" data-toggle="tab">进程列表</a></li>
            <li ng-class="'active' | iftrue:activeTabName=='other'"><a href="#other" ng-click="tab_sec('other')" data-toggle="tab">待续</a></li>
            <li class="pull-right" ng-show="activeTabName=='list'">
                <button class="btn btn-default btn-sm" title="当前进程数量" ng-show="process && process.total">数量: {{process.total}}</button>
                <div class="btn-group btn-group-sm">
                    <button class="btn btn-default" title="刷新进程列表" ng-click="refresh()" ng-disabled="auto_refresh"><i class="glyphicon glyphicon-refresh"></i></button>
                    <button class="btn btn-default" title="开启自动刷新" ng-click="auto_refresh_open()" ng-disabled="auto_refresh"><i class="glyphicon glyphicon-play"></i></button>
                    <button class="btn btn-default" title="关闭自动刷新" ng-click="auto_refresh_close()" ng-disabled="!auto_refresh"><i class="glyphicon glyphicon-stop"></i></button>
                </div>
            </li>
        </ul>
        <div class="tab-content">
            <div class="tab-pane" ng-class="'active' | iftrue:activeTabName=='list'" id="list">
                <div ng-show="init_process"><div waiting></div></div>
                <div ng-show="!init_process">
                    <table class="table table-hover table-bordered table-condensed">
                        <thead>
                            <tr>
                                <th style="width:50px;">#</th>
                                <th style="width:50px;">状态</th>
                                <th style="width:50px;">PID</th>
                                <th>名称</th>
                                <th>父进程</th>
                                <th>文件句柄</th>
                                <th>物理内存</th>
                                <th>虚拟内存</th>
                                <th style="width:130px">操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr ng-repeat="info in process.process">
                                <td>{{$index+1}}</td>
                                <td ng-bind-html-unsafe="info.state | process.status"></td>
                                <td>{{info.pid}}</td>
                                <td>{{info.name}}</td>
                                <td>{{info.ppid}}</td>
                                <td>{{info.fdsize}}</td>
                                <td>{{info.vmrss * 1024 | bytes2human}}</td>
                                <td>{{info.vmsize * 1024 | bytes2human}}</td>
                                <td>
                                    <button class="btn btn-default btn-xs" ng-click="process_detail(info)">查看</button>
                                    <button class="btn btn-default btn-xs" ng-click="processkillconfirm(info)">终止</button>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="tab-pane" ng-class="'active' | iftrue:activeTabName=='other'" id="other">
                待开发功能
            </div>
        </div>
    </div>

</div>


<div id="processkillconfirm" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title">终止进程 {{delete_process.name}}</h3>
            </div>
            <div class="modal-body">
                <p>确定终止进程 {{delete_process.name}} [PID: {{delete_process.pid}}] 吗？</p>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">取消</button>
                <button class="btn btn-danger" onclick="$('#processkillconfirm').modal('hide')" ng-click="processkill()">确认</button>
            </div>
        </div>
    </div>
</div>

<div id="process_detail_dialog" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title">进程详情 {{current_process.name}}</h3>
            </div>
            <div class="modal-body">
                <div class="tabbable">
                    <ul class="nav nav-tabs" role="tablist">
                        <li role="presentation" class="active"><a href="#info" aria-controls="info" role="tab" data-toggle="tab">信息</a></li>
                        <li role="presentation"><a href="#status" aria-controls="status" role="tab" data-toggle="tab">状态</a></li>
                        <li role="presentation"><a href="#file" aria-controls="file" role="tab" data-toggle="tab">文件</a></li>
                        <li role="presentation"><a href="#io" aria-controls="io" role="tab" data-toggle="tab">IO</a></li>
                        <li role="presentation"><a href="#memory" aria-controls="memory" role="tab" data-toggle="tab">内存</a></li>
                        <li role="presentation"><a href="#network" aria-controls="network" role="tab" data-toggle="tab">网络</a></li>
                        <button class="btn btn-default pull-right" title="刷新" ng-click="load_detial(current_process.pid)"><i class="glyphicon glyphicon-refresh"></i></button>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active" id="info" role="tabpanel">
                            <div ng-show="!current_process_loaded.info">
                                <div waiting ng-init="waitingText='正在加载中，请稍候...'"></div>
                            </div>
                            <div ng-show="current_process_loaded.info && current_process.info">
                                {{current_process.info}}
                            </div>
                        </div>
                        <div class="tab-pane" id="status" role="tabpanel">
                            <div ng-show="!current_process_loaded.status">
                                <div waiting ng-init="waitingText='正在加载中，请稍候...'"></div>
                            </div>
                            <table class="table table-bordered table-condensed" ng-show="current_process_loaded.status && current_process.status">
                                <tbody>
                                    <tr><td>Name</td><td>{{current_process.status.name}}</td></tr>
                                    <tr><td>Tgid</td><td>{{current_process.status.tgid}}</td></tr>
                                    <tr><td>Pid</td><td>{{current_process.status.pid}}</td></tr>
                                    <tr><td>状态</td><td ng-bind-html-unsafe="current_process.status.state | process.status"></td></tr>
                                    <tr><td>PPid</td><td>{{current_process.status.ppid}}</td></tr>
                                    <tr><td>FDSize</td><td>{{current_process.status.fdsize}}</td></tr>
                                    <tr><td>Groups</td><td>{{current_process.status.groups}}</td></tr>
                                    <tr><td>VmPeak</td><td>{{current_process.status.vmpeak[0]}} {{current_process.status.vmpeak[1]}}</td></tr>
                                    <tr><td>VmSize</td><td>{{current_process.status.vmsize[0]}} {{current_process.status.vmsize[1]}}</td></tr>
                                    <tr><td>VmLck</td><td>{{current_process.status.vmlock[0]}} {{current_process.status.vmlock[1]}}</td></tr>
                                    <tr><td>VmHWM</td><td>{{current_process.status.vmhwm[0]}} {{current_process.status.vmhwm[1]}}</td></tr>
                                    <tr><td>VmRSS</td><td>{{current_process.status.vmrss[0]}} {{current_process.status.vmrss[1]}}</td></tr>
                                    <tr><td>VmData</td><td>{{current_process.status.vmdata[0]}} {{current_process.status.vmdata[1]}}</td></tr>
                                    <tr><td>VmStk</td><td>{{current_process.status.vmstk[0]}} {{current_process.status.vmstk[1]}}</td></tr>
                                    <tr><td>VmExe</td><td>{{current_process.status.vmexe[0]}} {{current_process.status.vmexe[1]}}</td></tr>
                                    <tr><td>VmLib</td><td>{{current_process.status.vmlib[0]}} {{current_process.status.vmlib[1]}}</td></tr>
                                    <tr><td>VmPTE</td><td>{{current_process.status.vmpte[0]}} {{current_process.status.vmpte[1]}}</td></tr>
                                    <tr><td>VmSwap</td><td>{{current_process.status.vmswap[0]}} {{current_process.status.vmswap[1]}}</td></tr>
                                </tbody>
                            </table>
                        </div>
                        <div class="tab-pane" id="file" role="tabpanel">
                            <div ng-show="!current_process_loaded.file">
                                <div waiting ng-init="waitingText='正在加载中，请稍候...'"></div>
                            </div>
                            <div ng-show="current_process_loaded.file && current_process.file">
                                {{current_process.file}}
                            </div>
                        </div>
                        <div class="tab-pane" id="io" role="tabpanel">
                            <div ng-show="!current_process_loaded.io">
                                <div waiting ng-init="waitingText='正在加载中，请稍候...'"></div>
                            </div>
                            <table class="table table-bordered table-condensed" ng-show="current_process_loaded.io && current_process.io">
                                <thead>
                                    <tr>
                                        <th class="text-center">已读取</th>
                                        <th class="text-center">已写入</th>
                                        <th class="text-center">总读取</th>
                                        <th class="text-center">总写入</th>
                                        <th class="text-center">取消写入</th>
                                        <th class="text-center">读取次数</th>
                                        <th class="text-center">写入次数</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td class="text-center" title="实际从磁盘中读取的字节总数">{{current_process.io.read_bytes | bytes2human}}</td>
                                        <td class="text-center" title="实际写入到磁盘中的字节总数">{{current_process.io.write_bytes | bytes2human}}</td>
                                        <td class="text-center" title="读出的总字节数">{{current_process.io.rchar | bytes2human}}</td>
                                        <td class="text-center" title="写入的总字节数">{{current_process.io.wchar | bytes2human}}</td>
                                        <td class="text-center" title="取消写入的总字节数">{{current_process.io.cancelled_write_bytes | bytes2human}}</td>
                                        <td class="text-center" title="读取磁盘的调用次数">{{current_process.io.syscr}}</td>
                                        <td class="text-center" title="写入磁盘的调用次数">{{current_process.io.syscw}}</td>
                                    </tr>
                                </tbody>
                            </table>
                            <div class="alert alert-info">
                                <p>说明：</p>
                                <ul>
                                    <li>已读取：实际从磁盘中读取的字节总数</li>
                                    <li>已写入：实际写入到磁盘中的字节总数</li>
                                    <li>总读取：读出的总字节数，read()或者pread()中的长度参数总和(pagecache中统计而来，不代表实际磁盘的读入)</li>
                                    <li>总写入：写入的总字节数，write()或者pwrite()中的长度参数总和</li>
                                    <li>取消写入：取消写入的总字节数，由于截断pagecache导致应该发生而没有发生的写入字节数</li>
                                    <li>读取次数：读取磁盘的调用次数，read()或者pread()总的调用次数</li>
                                    <li>写入次数：写入磁盘的调用次数，write()或者pwrite()总的调用次数</li>
                                </ul>
                            </div>
                        </div>
                        <div class="tab-pane" id="memory" role="tabpanel">
                            <div ng-show="!current_process_loaded.memory">
                                <div waiting ng-init="waitingText='正在加载中，请稍候...'"></div>
                            </div>
                            <div>正在调试</div>
                            <table class="table table-bordered table-condensed" ng-show="current_process_loaded.memory && current_process.memory">
                                <thead>
                                    <tr>
                                        <th class="text-center">虚拟空间</th>
                                        <th class="text-center">物理内存</th>
                                        <th class="text-center">共享</th>
                                        <th class="text-center">可执行内存</th>
                                        <th class="text-center">虚拟库</th>
                                        <th class="text-center">数据栈</th>
                                        <th class="text-center">脏页数量</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td class="text-center" title="任务虚拟地址空间大小">{{(current_process.memory[0] * 4096) | bytes2human}}</td>
                                        <td class="text-center" title="正在使用的物理内存大小">{{(current_process.memory[1] * 4096) | bytes2human}}</td>
                                        <td class="text-center" title="共享页数">{{(current_process.memory[2]*4096) | bytes2human}}</td>
                                        <td class="text-center" title="程序所拥有的可执行虚拟内存大小">{{(current_process.memory[3]*4096) | bytes2human}}</td>
                                        <td class="text-center" title="被映像倒任务的虚拟内存空间的库的大小">{{(current_process.memory[4]*4096) | bytes2human}}</td>
                                        <td class="text-center" title="程序数据段和用户态的栈的大小">{{(current_process.memory[5]*4096) | bytes2human}}</td>
                                        <td class="text-center" title="脏页数量">{{current_process.memory[6]}}</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                        <div class="tab-pane" id="network" role="tabpanel">
                            <div ng-show="!current_process_loaded.network">
                                <div waiting ng-init="waitingText='正在加载中，请稍候...'"></div>
                            </div>
                            <div ng-show="current_process_loaded.network && current_process.network">
                                {{current_process.network}}
                            </div>
                        </div>
                    </div>
                </div>

            </div>
            <div class="modal-footer">
                <!-- <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button> -->
                <button class="btn btn-default" onclick="$('#process_detail_dialog').modal('hide')" ng-click="process_detail_close()">关闭</button>
            </div>
        </div>
    </div>
</div>